package com.grass.p019lv.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AdInfoBean;
import com.androidx.p013lv.base.bean.TagVideoBean;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.AdUtils;
import com.androidx.p013lv.base.utils.NetUtil;
import com.grass.p019lv.adapter.AvAreaStationAdapter;
import com.grass.p019lv.databinding.FragmentSearchLabelBinding;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.ArrayList;

/* renamed from: com.grass.lv.fragment.SearchLabelFragment */
public class SearchLabelFragment extends LazyFragment<FragmentSearchLabelBinding> implements OnRefreshLoadMoreListener, ItemClickListener {
    String HTTP_TAG = "queryVideoMore";
    AvAreaStationAdapter adapter;
    private int choiceSort;
    int count = 0;
    int lastId = 0;
    private String title;

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_search_label;
    }

    public static SearchLabelFragment newInstance(int i, String str) {
        Bundle bundle = new Bundle();
        SearchLabelFragment searchLabelFragment = new SearchLabelFragment();
        bundle.putInt("position", i);
        bundle.putString(Key.TITLE, str);
        searchLabelFragment.setArguments(bundle);
        return searchLabelFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentSearchLabelBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentSearchLabelBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentSearchLabelBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        AvAreaStationAdapter avAreaStationAdapter = new AvAreaStationAdapter();
        this.adapter = avAreaStationAdapter;
        avAreaStationAdapter.setItemListener(this);
        ((FragmentSearchLabelBinding) this.binding).recycler.setAdapter(this.adapter);
        ((FragmentSearchLabelBinding) this.binding).statuLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.fragment.SearchLabelFragment.View$OnClickListenerC30061 */

            public void onClick(View view) {
                if (!SearchLabelFragment.this.isOnClick()) {
                    SearchLabelFragment.this.lastId = 0;
                    SearchLabelFragment.this.getInfo();
                }
            }
        });
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void onFirstUserVisible() {
        super.onFirstUserVisible();
        this.choiceSort = getArguments().getInt("position");
        this.title = getArguments().getString(Key.TITLE);
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.lastId == 0) {
            AvAreaStationAdapter avAreaStationAdapter = this.adapter;
            if (!(avAreaStationAdapter == null || avAreaStationAdapter.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((FragmentSearchLabelBinding) this.binding).statuLayout.showNoNet();
                return;
            }
            ((FragmentSearchLabelBinding) this.binding).statuLayout.showLoading();
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryVideoByTag(this.choiceSort, this.lastId, this.title), new HttpCallback<BaseRes<TagVideoBean>>(this.HTTP_TAG) {
            /* class com.grass.p019lv.fragment.SearchLabelFragment.C30072 */

            public void onLvSuccess(BaseRes<TagVideoBean> baseRes) {
                if (SearchLabelFragment.this.binding != null) {
                    ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).statuLayout.hideLoading();
                    ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).refresh.finishRefresh();
                    ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).refresh.finishLoadMore();
                    if (baseRes.getCode() == 200) {
                        if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                            SearchLabelFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                            SearchLabelFragment.this.count = 0;
                            int adIntervalNum = AdUtils.getInstance().getAdIntervalNum(Constance.AD_HORIZONTAL);
                            if (AdUtils.getInstance().getAd(Constance.AD_HORIZONTAL) != null) {
                                for (int i = 0; i < baseRes.getData().getData().size(); i++) {
                                    if (SearchLabelFragment.this.count == adIntervalNum) {
                                        AdInfoBean ad = AdUtils.getInstance().getAd(Constance.AD_HORIZONTAL);
                                        VideoBean videoBean = new VideoBean();
                                        videoBean.setAd(true);
                                        ArrayList arrayList = new ArrayList();
                                        arrayList.add(ad.getAdImage());
                                        videoBean.setCoverImg(arrayList);
                                        videoBean.setAdInfoBean(ad);
                                        baseRes.getData().getData().add(i, videoBean);
                                        SearchLabelFragment.this.count = 0;
                                    } else {
                                        SearchLabelFragment.this.count++;
                                    }
                                }
                            }
                            if (SearchLabelFragment.this.lastId == 0) {
                                SearchLabelFragment.this.adapter.setData(baseRes.getData().getData());
                                ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).refresh.resetNoMoreData();
                                return;
                            }
                            SearchLabelFragment.this.adapter.setDatasInEnd(baseRes.getData().getData());
                        } else if (SearchLabelFragment.this.lastId == 0) {
                            ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).statuLayout.showEmpty();
                        } else {
                            ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                        }
                    } else if (SearchLabelFragment.this.lastId == 0) {
                        ((FragmentSearchLabelBinding) SearchLabelFragment.this.binding).statuLayout.showError();
                    }
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        AvAreaStationAdapter avAreaStationAdapter = this.adapter;
        if (avAreaStationAdapter == null || avAreaStationAdapter.getData() == null || this.adapter.getData().size() == 0) {
            ((FragmentSearchLabelBinding) this.binding).refresh.finishLoadMore();
            return;
        }
        this.lastId = ((VideoBean) this.adapter.getLastDataInPosition()).getVideoId();
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0;
        getInfo();
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
        super.onDestroyView();
    }
}
